﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using EntLibContrib.ExceptionHandling.Configuration;

namespace EntLibContrib.ExceptionHandling.Design
{
    /// <summary>
    /// Represents a <see cref="EntLibExtensions.Configuration.ErrorCodeEntry"/> configuration element. 
    /// </summary>
    [Image(typeof(ConfigurationSourceElementNode))]
    [SelectedImage(typeof(ConfigurationSourceElementNode))]
    public class ErrorCodeEntryNode : Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ConfigurationNode
    {
        /// <summary>
        /// Initialize a new instance of the <see cref="ErrorCodeEntryNode"/> class.
        /// </summary>
        public ErrorCodeEntryNode()
            : this(new ErrorCodeEntryData(Resources.ErrorCodeEntryNodeName))
        {
        }

        /// <summary>
        /// Initialize a new instance of the <see cref="ErrorCodeEntryNode"/> class with a <see cref="EntLibExtensions.Configuration.ErrorCodeEntry"/> instance.
        /// </summary>
        /// <param name="data">A <see cref="EntLibExtensions.Configuration.ErrorCodeEntry"/> instance</param>
        public ErrorCodeEntryNode(ErrorCodeEntryData data)
        {
            if (null == data) throw new ArgumentNullException("data");

            Rename(data.Name);
            this.errorCode = data.ErrorCode;
            this.wrapExceptionTypeName = data.WrapExceptionTypeName;
            this.exceptionMessage = data.ExceptionMessage;
        }

        /// <summary>
        /// Gets the <see cref="EntLibExtensions.Configuration.ErrorCodeEntry"/> this node represents.
        /// </summary>
        /// <value>
        /// The <see cref="EntLibExtensions.Configuration.ErrorCodeEntry"/> this node represents.
        /// </value>
        [Browsable(false)]
        public ErrorCodeEntryData ErrorCodeEntry
        {
            get
            {
                EntLibContrib.ExceptionHandling.Configuration.ErrorCodeEntryData data = new EntLibContrib.ExceptionHandling.Configuration.ErrorCodeEntryData(this.Name);
                data.ErrorCode = this.errorCode;
                data.WrapExceptionTypeName = this.wrapExceptionTypeName;
                data.ExceptionMessage = this.exceptionMessage;
                return data;
            }
        }

        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="ErrorCodeEntryNode"/> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
            }
            base.Dispose(disposing);
        }

        private System.Int32 errorCode;
        /// <summary>
        /// 
        /// </summary>
        /// <value>
        /// 
        /// </value>
        [SRDescription("ErrorCodeDescription", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public System.Int32 ErrorCode
        {
            get { return this.errorCode; }
            set { this.errorCode = value; }
        }

        private System.String wrapExceptionTypeName;
        /// <summary>
        /// 
        /// </summary>
        /// <value>
        /// 
        /// </value>
        [SRDescription("WrapExceptionTypeNameDescription", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        [Editor(typeof(TypeSelectorEditor), typeof(UITypeEditor))]
        [BaseType(typeof(Exception), TypeSelectorIncludes.BaseType)]
        public System.String WrapExceptionTypeName
        {
            get { return this.wrapExceptionTypeName; }
            set { this.wrapExceptionTypeName = value; }
        }

        private System.String exceptionMessage;
        /// <summary>
        /// 
        /// </summary>
        /// <value>
        /// 
        /// </value>
        [SRDescription("ExceptionMessageDescription", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public System.String ExceptionMessage
        {
            get { return this.exceptionMessage; }
            set { this.exceptionMessage = value; }
        }

    }
}
